package iso3.pt.action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import iso3.pt.dao.IncorrectPasswordException;
import iso3.pt.dao.UserNotFoundException;
import iso3.pt.model.Alumno;
import iso3.pt.model.Profesor;
import iso3.pt.service.PtDaoService;
import iso3.pt.service.PtService;

import java.util.Map;


public class Enrol  extends ActionSupport {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private PtService service = new PtDaoService();

	public String execute() throws Exception 
	{
		// Obtener alumno
		@SuppressWarnings("rawtypes")
		Map session = ActionContext.getContext().getSession();
		Alumno alumno = (Alumno) session.get("alumno");
		
		// Obtener asignatura
//		service.getAsignaturas()
		
		// Matricular
		service.matricular(alumno.getDni(), Integer.valueOf(getSelector()));
		
		return SUCCESS;
		
//        System.out.println("Validating login");
//        
//		if (getUsername() == null || getPassword() == null) 
//		{
//			addActionError("Compulsory to specify both username and password!");
//			return INPUT;
//		}
//		else
//		{
//			session = ActionContext.getContext().getSession();
//			
//			try
//			{
//				if (getSelector().equals("1"))
//				{
//					alumno = service.loginAlumno(Integer.valueOf(getUsername()), getPassword());
//					session.put("alumno", alumno);
//					return "listStudentSubjects";
//				}
//				else
//				{
//					Profesor profesor = service.loginProfesor(Integer.valueOf(getUsername()), getPassword());
//					session.put("profesor", profesor);
//					return "listLecturerSubjects";
//				}
//			} 
//			catch (UserNotFoundException e)
//			{
//				addActionError(getText("errors.invalid.login.user"));
//	            return ERROR;
//			}
//			catch (NumberFormatException e)
//			{
//				addActionError(getText("errors.invalid.login.user"));
//	            return ERROR;
//			}
//	        catch (IncorrectPasswordException e)
//	        {
//	        	addActionError(getText("errors.invalid.login.password"));
//	            return ERROR;
//	        }		
//		}
	}


    // ---- Username property ----

    /**
     * <p>Field to store User username.</p>
     * <p/>
     */
    private String username = null;


    /**
     * <p>Provide User username.</p>
     *
     * @return Returns the User username.
     */
    public String getUsername() {
        return username;
    }

    /**
     * <p>Store new User username</p>
     *
     * @param value The username to set.
     */
    public void setUsername(String value) {
        username = value;
    }

    // ---- Username property ----

    /**
     * <p>Field to store User password.</p>
     * <p/>
     */
    private String password = null;


    /**
     * <p>Provide User password.</p>
     *
     * @return Returns the User password.
     */
    public String getPassword() {
        return password;
    }

    /**
     * <p>Store new User password</p>
     *
     * @param value The password to set.
     */
    public void setPassword(String value) {
        password = value;
    }
    
	private String selector = null;
    
	public String getSelector() 
	{
		return selector;
	}

	public void setSelector(String selector) 
	{
		this.selector = selector;
	}

}
